<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>文章列表--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<!--给用户分配角色的弹出层-->
<div style="padding: 10px;"  id="selectUserRoleDiv">
    <table class="layui-hide" id="roleTable" lay-filter="roleTable"></table>
    <input type="hidden" id="userIdHiden"></input>
    <button type="button" class="layui-btn" id="assignRoleBtn">分配角色</button>
</div>
<script type="text/javascript" src="/static/layui/layui/layui.js"></script>
<script>
    layui.use(['form','layer','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table;

        var uuid=$('#userIdHiden').val();
        table.render({
            elem:'#roleTable',
            url:'/sys/initRoleByUserId',
            //将用户id传到后台去
            where:{
                uid:uuid
            },
            cols:[ [
                {type:'checkbox',align:'center'},
                {field:'id',title:'ID',align:'center'},
                {field:'name',title:'角色名称',align:'center'},
                {field:'remarks',title:'角色备注',align:'center'}
            ] ]
        });
        /**
         * 单击分配角色按钮触发重新分配的角色的操作
         */
        $("#assignRoleBtn").click(function () {
            //获取选中的角色id的集合
            var checkStatus = table.checkStatus('roleTable');
            var rids=new Array();
            $.each(checkStatus.data,function (index,item) {
                rids.push(item.id);
            });
            $.get("/sys/assignRole.html",{rids:rids,uid:uuid},function (res) {
                var rs=JSON.parse(res);
                layer.msg(rs.msg);
            });

        });
    })
</script>
</body>
</html>
